<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="" onsubmit="return post()">
        姓名:
        <input  type="checkbox" error="请勾选名字">
        请勾选协议:
        <input type="checkbox" error="请勾选协议">
        <input type="submit"/>
    </form>
    <script>

function post(){
    let map=new Map();
    let inputs=  document.querySelectorAll("[error]");
     inputs.forEach(item=>{
         map.set(item,{
             error:item.getAttribute("error"),//相当于做了个标签
                                              //方便后面调用
             status:item.checked
         })
     });
    return  [...map].every(([item,config])=>{
         config.status || alert(config.error);
         return config.error;
     })
    }

    </script>
</body>
</html>